import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Leetcode884 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(uncommonFromSentences("this apple is sweet", "this apple is sour")));
    }

    public static String[] uncommonFromSentences(String s1, String s2) {
        return Stream.concat(Arrays.stream(s1.split(" ")), Arrays.stream(s2.split(" ")))
                     .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
                     .entrySet()
                     .stream()
                     .filter(entry -> entry.getValue() == 1)
                     .map(Map.Entry::getKey)
                     .toArray(String[]::new);
    }
}
